/* Copyright (C) 2011  Till Schoenbein mail: tschoenbein[at]gmail.com
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
package de.shb.dice;

import java.util.ArrayList;

public class DiceResult {

	private int number = 0;

	private int eyes = 0;

	private ArrayList<Integer> results;

	public DiceResult(String dices) {
		number = Integer.parseInt(dices.substring(0, dices.indexOf("W")));
		eyes = Integer.parseInt(dices.substring(dices.indexOf("W")+1));
		System.out.println("INFO DiceResult: "+number + ", " + eyes);
		IDice dice = DiceFactory.getDice(eyes);
		
		results = new ArrayList<Integer>(number);

		for (int i = 0; i < number; i++) {
			System.out.println("TRACE DiceResult i="+i);
			results.add(dice.rollDice());
		}
	}

	public int getResult(int index) {
		return results.get(index);
	}

	public int getNumber() {
		return number;
	}

	public int getEyes() {
		return eyes;
	}

	public String toString() {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < number; i++) {
			System.out.println("TRACE DiceResult.toString i="+i);
			builder.append(results.get(i));
			if (i != number - 1)
				builder.append(", ");
		}
		return builder.toString();
	}

}
